﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for ThongTinCongTyProvider
/// Author      toanvt
/// CreatedDate  7/12/2011
/// </summary>
namespace EHTWebsite.Code
{
    public class ThongTinCongTyProvider
    {

        /// <summary>
        /// Author      toanvt
        /// CreatedDate  7/12/2011
        /// </summary>
        /// <param name="theThongTinCongTy">Đối tượng mang thông tin cơ bản công ty</param>
        public static void IUThongTinCongTys(ThongTinCongTy theThongTinCongTy, Boolean isAdd)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_IUThongTinCongTys";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@CongTyID", theThongTinCongTy.CongTyID));
            command.Parameters.Add(new SqlParameter("@TenCongTyVN", theThongTinCongTy.TenCongTyVN));
            command.Parameters.Add(new SqlParameter("@TenCongTyOther", theThongTinCongTy.TenCongTyOther));
            command.Parameters.Add(new SqlParameter("@DiaChiVN", theThongTinCongTy.DiaChiVN));
            command.Parameters.Add(new SqlParameter("@DiaChiOther", theThongTinCongTy.DiaChiOther));
            command.Parameters.Add(new SqlParameter("@Email", theThongTinCongTy.Email));
            command.Parameters.Add(new SqlParameter("@EmailPass", theThongTinCongTy.EmailPass));
            command.Parameters.Add(new SqlParameter("@DienThoai", theThongTinCongTy.DienThoai));
            command.Parameters.Add(new SqlParameter("@Hotline", theThongTinCongTy.Hotline));
            command.Parameters.Add(new SqlParameter("@Website", theThongTinCongTy.Website));
            command.Parameters.Add(new SqlParameter("@SologanVN", theThongTinCongTy.SologanVN));
            command.Parameters.Add(new SqlParameter("@SologanOther", theThongTinCongTy.SologanOther));
            command.Parameters.Add(new SqlParameter("@LogoUrl", theThongTinCongTy.LogoUrl));
            command.Parameters.Add(new SqlParameter("@MaSoThue", theThongTinCongTy.MaSoThue));
            command.Parameters.Add(new SqlParameter("@TaiKhoan", theThongTinCongTy.TaiKhoan));
            command.Parameters.Add(new SqlParameter("@GioiThieuTomTatVN", theThongTinCongTy.GioiThieuTomTatVN));
            command.Parameters.Add(new SqlParameter("@GioiThieuTomTatOther", theThongTinCongTy.GioiThieuTomTatOther));
            command.Parameters.Add(new SqlParameter("@GioiThieuVN", theThongTinCongTy.GioiThieuVN));
            command.Parameters.Add(new SqlParameter("@GioiThieuOther", theThongTinCongTy.GioiThieuOther));
            command.Parameters.Add(new SqlParameter("@Fax", theThongTinCongTy.Fax));
            command.Parameters.Add(new SqlParameter("@IsAdd", isAdd));
            DataProvider.ExecuteNoneQuery(command);

        }

        /// <summary>
        /// Author      toanvt
        /// CreatedDate  7/12/2011
        /// </summary>
        /// <param name="congTyID">Mã công ty</param>
        /// <returns>Dối tượng chứa thông tin công ty</returns>
        public static ThongTinCongTy GetThongTinCongTyByCongTyID(Int32 congTyID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetThongTinCongTyByCongTyID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@CongTyID", congTyID));
            DataSet ds = DataProvider.ExecuteDataSet(command);
            ThongTinCongTy theThongTinCongTy = null;

            if (ds.Tables[0].Rows.Count > 0)
            {
                theThongTinCongTy = new ThongTinCongTy();
                theThongTinCongTy.CongTyID = Int32.Parse(ds.Tables[0].Rows[0]["CongTyID"].ToString());
                theThongTinCongTy.DiaChiOther = ds.Tables[0].Rows[0]["DiaChiOther"].ToString();

                theThongTinCongTy.DichVuTomTatOther = ds.Tables[0].Rows[0]["DichVuTomTatOther"].ToString();
                theThongTinCongTy.DichVuTomTatVN = ds.Tables[0].Rows[0]["DichVuTomTatVN"].ToString();
                theThongTinCongTy.DiaChiVN = ds.Tables[0].Rows[0]["DiaChiVN"].ToString();
                theThongTinCongTy.DichVuOther = ds.Tables[0].Rows[0]["DichVuOther"].ToString();

                theThongTinCongTy.DichVuVN = ds.Tables[0].Rows[0]["DichVuVN"].ToString();
                theThongTinCongTy.Hotline = ds.Tables[0].Rows[0]["Hotline"].ToString();
                theThongTinCongTy.DienThoai = ds.Tables[0].Rows[0]["DienThoai"].ToString();
                theThongTinCongTy.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                theThongTinCongTy.EmailPass = ds.Tables[0].Rows[0]["EmailPass"].ToString();

                theThongTinCongTy.GioiThieuTomTatOther = ds.Tables[0].Rows[0]["GioiThieuTomTatOther"].ToString();
                theThongTinCongTy.GioiThieuTomTatVN = ds.Tables[0].Rows[0]["GioiThieuTomTatVN"].ToString();
                theThongTinCongTy.GioiThieuOther = ds.Tables[0].Rows[0]["GioiThieuOther"].ToString();
                theThongTinCongTy.GioiThieuVN = ds.Tables[0].Rows[0]["GioiThieuVN"].ToString();

                theThongTinCongTy.LogoUrl = ds.Tables[0].Rows[0]["LogoUrl"].ToString();
                theThongTinCongTy.LuotTruyCap = Int32.Parse(ds.Tables[0].Rows[0]["LuotTruyCap"].ToString());
                theThongTinCongTy.MaSoThue = ds.Tables[0].Rows[0]["MaSoThue"].ToString();
                theThongTinCongTy.FooterOther = ds.Tables[0].Rows[0]["FooterOther"].ToString();
                theThongTinCongTy.FooterVN = ds.Tables[0].Rows[0]["FooterVN"].ToString();
               

                theThongTinCongTy.SologanOther = ds.Tables[0].Rows[0]["SologanOther"].ToString();
                theThongTinCongTy.SologanVN = ds.Tables[0].Rows[0]["SologanVN"].ToString();
                theThongTinCongTy.TaiKhoan = ds.Tables[0].Rows[0]["TaiKhoan"].ToString();
                theThongTinCongTy.TenCongTyOther = ds.Tables[0].Rows[0]["TenCongTyOther"].ToString();
                theThongTinCongTy.TenCongTyVN = ds.Tables[0].Rows[0]["TenCongTyVN"].ToString();
                theThongTinCongTy.Website = ds.Tables[0].Rows[0]["Website"].ToString();
                theThongTinCongTy.Fax = ds.Tables[0].Rows[0]["Fax"].ToString();
            }

            return theThongTinCongTy;
        }

        /// <summary>
        /// Author      toanvt
        /// CreatedDate  7/12/2011
        /// </summary>
        /// <param name="gioiThieuVN">Giới thiệu Việt Nam</param>
        /// <param name="gioiThieuOther">Giới thiệu Ngông ngữ khác</param>
        /// <param name="congTyID">Mã công ty</param>
        public static void UpdateGioiThieuByCongtyID(String gioiThieuVN, String gioiThieuOther, String gioiThieutomtatVN, String gioiThieutomtatOther, Int32 congTyID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_UpdateGioiThieuByCongTyID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@CongTyID", congTyID));
            command.Parameters.Add(new SqlParameter("@GioiThieuVN", gioiThieuVN));
            command.Parameters.Add(new SqlParameter("@GioiThieuOther", gioiThieuOther));
            command.Parameters.Add(new SqlParameter("@GioiThieuTomTatVN", gioiThieutomtatVN));
            command.Parameters.Add(new SqlParameter("@GioiThieuTomTatOther", gioiThieutomtatOther));

            DataProvider.ExecuteNoneQuery(command);
        }

        /// <summary>
        /// Author      toanvt
        /// CreatedDate  7/12/2011
        /// </summary>
        /// <param name="dichVuVN">Dịch vụ Việt Nam</param>
        /// <param name="dichVuOther">Dịch vụ Other</param>
        /// <param name="congtyID">Mã công ty</param>
        public static void UpdateDichVuByCongTyID(String dichVuVN, String dichVuOther, String dichVuTTVN, String dichVuTTOther, Int32 congtyID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_UpdateDichVuByCongTyID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@CongTyID", congtyID));
            command.Parameters.Add(new SqlParameter("@DichVuVN", dichVuVN));
            command.Parameters.Add(new SqlParameter("@DichVuOther", dichVuOther));
            command.Parameters.Add(new SqlParameter("@DichVuTomTatVN", dichVuTTVN));
            command.Parameters.Add(new SqlParameter("@DichVuTomTatOther", dichVuTTOther));

            DataProvider.ExecuteNoneQuery(command);
        }

        public static void DeleteThongtinCongty(Int32 congtyID)
        {             
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_DeleteThongTinCongTys";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@CongTyID", congtyID));
               DataProvider.ExecuteNoneQuery(command);
        }

        /// <summary>
        /// Author: toanvt
        /// CreatedDate: 7/12/2011
        /// </summary>
        /// <param name="CongTyID">Mã công ty</param>
        public static void InCreateLuotTruyCap(Int32 congTyID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_InCreateLuotTruyCap";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@CongTyID", congTyID));

            DataProvider.ExecuteNoneQuery(command);
        }

    }
}